﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace RFW.Weather.Forecast
{
	public class Moon
	{
		public string PercentIlluminated { get; set; }
		public string Age { get; set; }
		public string Sunset { get; set; }
		public string Sunrise { get; set; }

		internal void Process(XElement element)
		{
			Clear();

			var data = from o in element.Elements("moon_phase")
					   select new Moon
					   {
						   PercentIlluminated = o.Element("percentIlluminated").Value,
						   Age = o.Element("ageOfMoon").Value,
						   Sunset = o.Element("sunset").Element("hour").Value + ":" + o.Element("sunset").Element("minute").Value,
						   Sunrise = o.Element("sunrise").Element("hour").Value + ":" + o.Element("sunrise").Element("minute").Value,
					   };

			foreach (Moon o in data)
			{
				this.PercentIlluminated = o.PercentIlluminated;
				this.Age = o.Age;
				this.Sunset = o.Sunset;
				this.Sunrise = o.Sunrise;
			}
		}

		public void Clear()
		{
			this.PercentIlluminated = string.Empty;
			this.Age = string.Empty;
			this.Sunrise = string.Empty;
			this.Sunrise = string.Empty;
		}

		public static Moon Linq(XElement element)
		{
			Moon moon = new Moon();
			moon.Process(element);

			return moon;
		}
	}
}
